package main

import (
	"encoding/json"
	"fmt"
)

type IT struct {
	Subjects []string `json:"subjects"`
	Company string `json:"company"`
	IsOk bool	`json:"is_ok,string"`
	Price float64 `json:",string"`//如果`json:"-"`隐藏该字段
}

func main(){
	s:= IT{[]string{"go","docker","fabric"},"ITCompany",true,189.8}

	jsonObj,err := json.Marshal(s)
	if err != nil{
		return
	}
	fmt.Printf("%s\n",jsonObj)

	m := make(map[string]interface{})
	m["subjects"] = []string{"go","docker","fabric"}
	m["company"] = "ITCompany"
	m["isok"] = true
	m["price"] = 189.9

	jsonObj2,err := json.Marshal(m)
	if err != nil{
		return
	}
	fmt.Printf("%s\n",jsonObj2)


	//json转化为struct
	var temp IT
	jsonf := `{"subjects":["go","docker","fabric"],"company":"ITCompany","is_ok":"true","Price":"189.8"}`
	err = json.Unmarshal([]byte(jsonf),&temp)
	if err != nil{
		return
	}
	fmt.Printf("temp=%v,temp.company=%v\n",temp,temp.Company)

}
